const path = require('path')
const Koa = require('koa')
const koaJsonError = require("koa-json-error");
const { koaBody } = require("koa-body");
const koaStatic = require("koa-static");

const router = require('../router/index')

const app = new Koa()
app
.use(koaJsonError({
  format: (err) => ({
    code: err.status,
    message: err.message,
    result: err.stack,
  }),
}))
.use(
  koaBody({
    multipart: true,
    formidable: {
      maxFieldsSize: 200 * 1024 * 1024,
      keepExtensions: true,
      // uploadDir: path.join(__dirname, "../static"),
      // keepExtensions: true,
      // onFileBegin(name, file) {
        // console.log(name, file, 'namefiel');
      // },
    },
  })
)
.use(koaStatic(path.join(__dirname, "../static")))
.use(router.routes())
.use(router.allowedMethods())
module.exports = app